package com.bsj.power.system.web;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.bsj.power.common.config.global.JsonResult;
import com.bsj.power.common.def.dto.menu.MenuDTO;
import com.bsj.power.common.def.dto.menu.MenuSearchDTO;
import com.bsj.power.common.def.vo.sys.menu.MenuTreeVO;
import com.bsj.power.common.def.vo.sys.menu.MenuVO;
import com.bsj.power.system.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/***
 * @description MenuController
 * @author LiJiaXin
 * @version 1.0.0
 * @time 2024/1/12 15:44
 **/
@RestController
@RequestMapping("/system/menu")
//@SaCheckPermission("/master/system/menu")
public class MenuController {

    @Autowired
    private MenuService menuService;

    /**
     * 添加权限
     *
     * @param menuDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/9/11 17:38
     */
    @PostMapping("/add")
    public JsonResult add(@Validated @RequestBody MenuDTO menuDTO) {
        return menuService.addMenu(menuDTO);
    }

    /**
     * 删除权限
     *
     * @param menuId
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/9/11 17:38
     */
    @PostMapping("/delete/{menuId}")
    public JsonResult delete(@PathVariable("menuId") Integer menuId) {
        return menuService.deleteMenu(menuId);
    }


    /**
     * 修改权限
     *
     * @param menuDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/9/11 17:38
     */
    @PostMapping("/update")
    public JsonResult update(@Validated @RequestBody MenuDTO menuDTO) {
        return menuService.updateMenu(menuDTO);
    }

    /**
     * 根据权限id获取权限信息
     *
     * @param menuId
     * @return com.bsj.power.common.config.global.JsonResult<com.bsj.power.common.def.vo.sys.menu.MenuVO>
     * @author ljx
     * @time 2024/9/11 17:38
     */
    @GetMapping("/getById/{menuId}")
    public JsonResult<MenuVO> getById(@PathVariable("menuId") Integer menuId) {
        return JsonResult.success(menuService.getMenuInfoById(menuId));
    }

    /**
     * 权限分页
     *
     * @param menuSearchDTO
     * @return com.bsj.power.common.config.global.JsonResult<java.util.List < com.bsj.power.common.def.vo.sys.menu.MenuVO>>
     * @author ljx
     * @time 2024/9/11 17:37
     */
    @GetMapping("/page")
    public JsonResult<List<MenuVO>> page(@Validated MenuSearchDTO menuSearchDTO) {
//        StpUtil.hasPermission("/master/system/menu");
        return menuService.pageMenu(menuSearchDTO);
    }

    /**
     * 权限树
     *
     * @return com.bsj.power.common.config.global.JsonResult<java.util.List < com.bsj.power.common.def.vo.sys.menu.MenuTreeVO>>
     * @author ljx
     * @time 2024/9/11 17:37
     */
    @GetMapping("/tree")
    public JsonResult<List<MenuTreeVO>> tree() {
        return JsonResult.success(menuService.getMenuTree());
    }


}
